// 1. 导入所需的包
import Vue from 'vue'
import Vuex from 'vuex'

// 2. 将Vuex注册为Vue的插件
Vue.use(Vuex)

// 3. 创建 store 实例对象
const store = new Vuex.Store({
  strict: true,
  /* 这里配置Vuex */
  state: {
    age: 20
  },
  mutations: {
    updatestate (state, n) {
      state.age += n
    }
  },
  actions: {
    updateAgeAfter (store, m) {
      setTimeout(() => {
        store.commit('updatestate', m)
      }, 1000)
    }
  },
  getters: {
    a (state) {
      return state.age * 2
    }
  }
})

// 4. 导出 store 对象
export default store
